﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Microsoft.ApplicationBlocks.Data;

namespace DanhMuc
{
    class DanTocInfo
    {
        private string _DanTocID;

        public string DanTocID
        {
            get { return _DanTocID; }
            set { _DanTocID = value; }
        }

        private string _TenDanToc;

        public string TenDanToc
        {
            get { return _TenDanToc; }
            set { _TenDanToc = value; }
        }

        private bool _Active;

        public bool Active
        {
            get { return _Active; }
            set { _Active = value; }
        }
    }

    class DanTocCtr
    {
        string strCnn = DBClass_FANIT82.GetConnectString();

        public void Insert(DanTocInfo Item)
        {
            SqlParameter[] Para = new SqlParameter[]
            {
                new SqlParameter("@DanTocID", Item.DanTocID),
                new SqlParameter("@TenDanToc", Item.TenDanToc == null ? (object)DBNull.Value:Item.TenDanToc),
                new SqlParameter("@Active", Item.Active == null ? (object)DBNull.Value:Item.Active)
            };
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.StoredProcedure, "D_DanToc_Insert", Para);
        }

        public void Update(DanTocInfo Item)
        {
            SqlParameter[] Para = new SqlParameter[]
            {
                new SqlParameter("@DanTocID", Item.DanTocID),
                new SqlParameter("@TenDanToc", Item.TenDanToc == null ? (object)DBNull.Value:Item.TenDanToc),
                new SqlParameter("@Active", Item.Active == null ? (object)DBNull.Value:Item.Active)
            };
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.StoredProcedure, "D_DanToc_Update", Para);
        }

        public void Delete(string  strDanTocID)
        {
            SqlParameter[] Para = new SqlParameter[]
            {
                new SqlParameter("@DanTocID", strDanTocID),
            };
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.StoredProcedure, "D_DanToc_Delete", Para);
        }

        public DataTable GetList()
        {
            DataSet Ds = SqlHelper.ExecuteDataset(strCnn, CommandType.StoredProcedure, "D_DanToc_GetList");
            return Ds.Tables[0];
        }

        public DanTocInfo GetByID(string DanTocID)
        {
            SqlDataReader dtr = SqlHelper.ExecuteReader(strCnn, CommandType.StoredProcedure, "D_DanToc_Get", new SqlParameter("DanTocID", DanTocID));
            DanTocInfo ObjDanToc = null;
            while (dtr.Read())
            {
                ObjDanToc = new DanTocInfo();
                ObjDanToc.DanTocID = dtr["DanTocID"].ToString();
                ObjDanToc.TenDanToc = dtr["TenDanToc"].ToString();
                ObjDanToc.Active = (bool)dtr["Active"];
            }
            return ObjDanToc;
        }
    }
}
